package psd.waveofminds.dao;

// Generated 22 Jan, 2010 12:31:40 AM by Hibernate Tools 3.2.4.GA

import java.util.List;
import javax.naming.InitialContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.SessionFactory;

import psd.waveofminds.pojo.Templateallot;
import static org.hibernate.criterion.Example.create;

/**
 * Home object for domain model class Templateallot.
 * @see psd.waveofminds.pojo.Templateallot
 * @author Hibernate Tools
 */
public class TemplateallotHome {

	private static final Log log = LogFactory.getLog(TemplateallotHome.class);

	private final SessionFactory sessionFactory = getSessionFactory();

	protected SessionFactory getSessionFactory() {
		try {
			return (SessionFactory) new InitialContext()
					.lookup("SessionFactory");
		} catch (Exception e) {
			log.error("Could not locate SessionFactory in JNDI", e);
			throw new IllegalStateException(
					"Could not locate SessionFactory in JNDI");
		}
	}

	public void persist(Templateallot transientInstance) {
		log.debug("persisting Templateallot instance");
		try {
			sessionFactory.getCurrentSession().persist(transientInstance);
			log.debug("persist successful");
		} catch (RuntimeException re) {
			log.error("persist failed", re);
			throw re;
		}
	}

	public void attachDirty(Templateallot instance) {
		log.debug("attaching dirty Templateallot instance");
		try {
			sessionFactory.getCurrentSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Templateallot instance) {
		log.debug("attaching clean Templateallot instance");
		try {
			sessionFactory.getCurrentSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void delete(Templateallot persistentInstance) {
		log.debug("deleting Templateallot instance");
		try {
			sessionFactory.getCurrentSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public Templateallot merge(Templateallot detachedInstance) {
		log.debug("merging Templateallot instance");
		try {
			Templateallot result = (Templateallot) sessionFactory
					.getCurrentSession().merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public Templateallot findById(psd.waveofminds.pojo.TemplateallotId id) {
		log.debug("getting Templateallot instance with id: " + id);
		try {
			Templateallot instance = (Templateallot) sessionFactory
					.getCurrentSession().get(
							"psd.waveofminds.pojo.Templateallot", id);
			if (instance == null) {
				log.debug("get successful, no instance found");
			} else {
				log.debug("get successful, instance found");
			}
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	@SuppressWarnings("unchecked")
	public List<Templateallot> findByExample(Templateallot instance) {
		log.debug("finding Templateallot instance by example");
		try {
			List<Templateallot> results = (List<Templateallot>) sessionFactory
					.getCurrentSession().createCriteria(
							"psd.waveofminds.pojo.Templateallot").add(
							create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}
}
